<template>
	<view class="content" style="background-color: #FFFFFF;">
		<u-row @click="toEdit" style="padding: 30rpx;">
			<u-col span="3">
				<u-avatar v-if="userInfo.avatar" :src="userInfo.avatar   " default-url="src7" size="70" shape="square">
				</u-avatar>
				<u-avatar v-else src='/static/logo.png' default-url="src7" size="70" shape="square">
				</u-avatar>
			</u-col>
			<u-col span="9">
				<u-row>
					<u-col span="8"> 
						<view v-if="login">
							<u-row >
								<u-col span="10">
									<u--text :text='`昵称：${userInfo.nick_name}`' size='15' color='#878787'></u--text>
								</u-col>
								 
							</u-row>
							<u-row v-if="false">
								<u-col span="4">
									<u--text text='注册时间:' size='12' color='#878787'></u--text>
								</u-col>
								<u-col span="6">
									<u--text    :text='`${userInfo.add_time}`'
										size='12' color='#878787'></u--text>
								</u-col>
							</u-row>
							<u-row class="u-m-t-15"  >
								<u-col span="12">
									<u--text :text='`会员到期时间：${ endTime}`' size='12' color='#878787'></u--text>
								</u-col>
								 
							</u-row>
						</view>
						<u-row class="u-m-t-15" v-else>
							<u-col span="6">
								<u-button type="primary" :plain="true" text="登录" size='small'></u-button>
								<!-- <u--text text='登录' size='18' color='#878787'></u--text> -->
							</u-col>
						</u-row>
					</u-col>
					<u-col span="4" v-if="login">
						<u-tag v-if="userInfo.level == -2" text="试用版" size="medium"
							icon="/static/icon/try.png" plain>
						</u-tag>
						<u-tag v-else-if="userInfo.level == 0" text="会员版" size="medium"
							icon="/static/icon/v1.png" plain> 
						</u-tag>
						<u-tag v-else-if="userInfo.level == 1" text="会员版" size="medium"
							icon="/static/icon/v2.png" plain> 
						</u-tag>
						<u-tag v-else-if="userInfo.level == 2" text="会员版" size="medium"
							icon="/static/icon/v3.png" plain> 
						</u-tag>
						<u-tag v-else text="非会员" size="medium" icon="/static/icon/overTime.png"
							plain>
						</u-tag>
					</u-col>
				</u-row>
			</u-col>
		</u-row>
		<u-row style="padding: 15rpx;">
		<u-line></u-line>
		</u-row>
		<u-cell-group :border='false'> 
			<u-cell v-if="false"   @click="navTo(0)" title="我的收藏" isLink icon="/static/icon/shop.png">
			</u-cell>
			 
			<u-cell @click="navTo(2)" title="我的身份"   isLink   :value='getUserType' ></u-cell>
			<!-- <u-cell @click="navTo(3)" title="我的轨迹" isLink icon="/static/icon/time.png"></u-cell> -->
			 
			<u-cell @click="navTo(4)" title="升级会员" isLink ></u-cell>
			<u-cell @click="navTo(5)" title="绑定手机" isLink :value='userInfo.mobile || "未绑定"'  >
			</u-cell>
		<!-- 	<u-cell @click="navTo(6)" title="分享有礼" isLink icon="/static/icon/share.png"></u-cell>
			<u-cell @click="navTo(7)" title="我的分享" isLink icon="/static/icon/frinds.png"></u-cell> -->
			<u-cell @click="navTo(6)"  v-if="userType  && userType == 3 || userType == 1|| userType == 2 " title="我的团推" isLink  ></u-cell>
			<!-- <u-cell @click="navTo(7)" title="意见反馈" isLink  ></u-cell> -->


			 
			<u-cell @click="exitLogin"  title="设置" isLink  ></u-cell>

		</u-cell-group>
 
		<u-toast ref="uToast"></u-toast>
		<u-action-sheet @select='sheetSlect' :actions="sheetOptions" cancelText='取消' @close='showSheet = false'
			:show="showSheet"></u-action-sheet>
	</view>
</template>

<script>
	var that
	let KMSID = require('../../../service/KMSID.js'),mKMSID
	import { mapState, mapGetters, mapActions, mapMutations } from 'vuex'
	// import cIsLogin from '@/static/js/cIsLogin.js'
	var UserInfo = require('../../../service/UserInfo.js'),
		mUserInfo ;
	import mInit from "../../../tools/Init"
	export default {

		data() {
			return {
				userType:'',
				token:'',
				value3:true,
				login: false,
				autoStatus: false,
				userInfo: {},
				popupShow: false,
				value5: 2,
				show: false,
				src: 'https://cdn.uviewui.com/uview/album/1.jpg',
				toast: {
					type: 'loading',
					title: '初始化中',
					message: "初始化中",
					duration: 6000,
					iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/loading.png'
				},
				showSheet:false,
				sheetOptions: [{
					index: 0,
					name: '驾校认证',
					color: '#000000',
					fontSize: '15'
				}, {
					index: 1,
					name: '教练认证',
				
					color: '#000000',
					fontSize: '15'
				}, {
					index: 2,
					name: '区域代理认证',
				
					color: '#000000',
					fontSize: '15'
				}],
			}
		},
		computed:{
			...mapState('login',['$userInfo']),
			endTime(){
				if(that.userInfo.vip_end_time){
					return that.userInfo.vip_end_time.substr(0,10)
				}else{
					return '暂无信息'
				}
			},
			getUserType(){
				let t = '学员'
				if(that.userInfo.types){
					that.userType = that.userInfo.types
				}
				if(that.userType == 1) t = '驾校'
				if(that.userType == 2) t = '教练'
				if(that.userType == 3) t = '区域代理'
				if(that.userType == 4) t = '经理'
				if(that.userType == 5) t = '学员'
 
				return t
			}
		},
		onLoad() {
			that = this
			// #ifdef APP-PLUS
			that.$forceUpdate()
			plus.screen.lockOrientation('portrait-primary');
			// #endif
			// mInit.init(this.mNetTool, res => {
			// 	console.log('mInit',res)
				
			// })
			mKMSID =  new KMSID(this.mNetTool)
			mUserInfo =  new UserInfo(this.mNetTool)
			
			mUserInfo.getInfo({},res=>{
				uni.setStorageSync('userInfo',res.rows)
			})
			
			
		},
		mounted() {
			let userInfo = uni.getStorageSync('userInfo')
			if (userInfo) {
				that.userInfo = userInfo
			}
			that.userType = uni.getStorageSync('userType')
		},
		onShow() {
			console.log('that.userInfo',that.userInfo)
			console.log('token',uni.getStorageSync('token'))
			console.log('setStorageSync',uni.getStorageSync('userInfo'))
			let token = uni.getStorageSync('token')
			let login = uni.getStorageSync('login') 
			if(token && login){
				that.token = token 
				that.login = login 
				
			}else{  
				that.login = false 
				this.$forceUpdate()
			}
			let userInfo = uni.getStorageSync('userInfo') 
 
		
			if(userInfo){
				that.userInfo= userInfo
				mKMSID.list({
					user_id:that.userInfo.id,
					dataOrderField:"id",
					 dataOrderType:"asc"
				},res=>{
					if(res.rows.length != 0){
						if(res.rows[0].epprove_status == 1){
							that.userType = res.rows[0].type
						}else if(res.rows[0].epprove_status == 3){
							that.userType = 0
						}
					}else{
						that.userType = false 
					}
					uni.setStorageSync('userType',that.userType)
					console.log('2222222222',res,that.userType)
					 
				})
			}else{
				that.userInfo= []
				this.$forceUpdate()
			}
			console.log('userInfo',userInfo)
			console.log('userInfolength',userInfo.length)
			
		},
		methods: {
			sheetSlect(e) {
				let userInfo = uni.getStorageSync('userInfo')
				if(userInfo.user_identity){
					let t
					if(userInfo.user_identity == 1) t = '驾校'
					if(userInfo.user_identity == 2) t = '教练'
					if(userInfo.user_identity == 3) t = '区域代理'
					if(userInfo.user_identity == 4) t = '经理'
					if(userInfo.user_identity == 5) t = '学员'
					uni.$u.toast('您已认证 '+t+' 身份')
					return
				}
				console.log(e)
				let type = 0
				if(e.index == 0){
					type=3
				}
				if(e.index == 1){
					type=1
				}
				if(e.index == 2){
					type=2
				}
 
				uni.setStorageSync('aplyIdenty',type)
				uni.navigateTo({
					url:'../getIdentity/getIdentity'
				})
			},
			getact(){
				uni.navigateTo({
					url:'../doActive/doActive'
				})
			},
			toEdit() {
				let that = this  
				if (!that.userInfo.id || !that.token) {
					uni.showModal({
						content: "您未登录，请先登录！",
						success(r) {
							if (r.confirm) {
								if (that.autoStatus) { //支持一键登录
									console.log('进入一键登录')
									that.keyLogin()
								} else {
									// // #ifdef MP-WEIXIN
									// uni.navigateTo({
									// 	url: '../login/keyLogin'
									// })
									// // #endif
									 
									uni.navigateTo({
										url: '../login/login'
									})
								 

								}

							}
						}
					})
					return
				}
				uni.navigateTo({
					url: 'userInfoEdit/userInfoEdit'
				})
			},
			exitLogin() {
				uni.navigateTo({
					url:'setting/setting'
				})
		 
			},
			close() {
				this.popupShow = false
				// console.log('close');
			},
			navTo(i) { 
				if(!uni.getStorageSync('login') && !uni.getStorageSync('login')){
					uni.$u.toast('请先登录')
					return
				}
				if(i == 2){ 
					let userInfo = uni.getStorageSync('userInfo')
					let types = Number(userInfo.types)
					console.log('types',types)
					if(types == 5) return
					let userType = that.userType
					if(types){
						userType  = types
					}
					console.log('userType',userType)
					// userType  && userType == 3 || userType == 1|| userType == 2 
					if(userType  && userType == 3 || userType == 1|| userType == 2){
						uni.setStorageSync('aplyIdenty',userType)
						uni.navigateTo({
							url:'../getIdentity/getIdentity'
						})
					}else{
						uni.navigateTo({
							url:'../login/identity/identity'
						})
					}
					return
					let type
					if(that.userType){
						  type=that.userType
						  uni.setStorageSync('aplyIdenty',type)
						  uni.navigateTo({
						  	url:'../getIdentity/getIdentity'
						  })
						  return
					}
					
					that.showSheet = true
					
					return
				}
				if(i == 5){
					//是否可以更换手机
					// if(that.userInfo.mobile){
					// 	uni.$u.toast('您已绑定，无需重复绑定')
					// 	return
					// }
				}
				console.log(i)
				let a = [
					'../myCollection/myCollection',
					'../myWays/myWays',
					'../getIdentity/getIdentity',
					'../mapLoacas/mapLoacas',
					'../VIP/VIP',
					'../bindPhone/bindPhone', 
					'../areaAgent/areaAgent',
					'../feedBack/feedBack',
					'../serviceContact/serviceContact',
				]
				uni.navigateTo({
					url: a[i]
				})
			}
		}
	}
</script>

<style lang="scss">
	.content {
		 
	}
</style>
